<?php
/**
 * Each engineer has a duty to keep the code elegant
 * Created by wolffy.
 * Author @wolffy<13750088090@sina.cn>
 * Date: 2018/8/14
 * Time: 17:39
 */
namespace App\Http\Controllers\Api\V1_8_8;

use App\Http\Requests\Api\V1_8_8\CollectMoneyBillRequest;
use App\Http\Requests\Api\V1_8_8\CreditCardHandleApplyRequest;
use App\Http\Requests\Api\V1_8_8\RepaymentAccountWithdrawRequest;
use App\Services\AlipayValidateCardInfo\BankCardInfoService;
use App\Services\CollectMoneyService;
use App\Services\CreditCardHandleApplyService;
use App\Services\CreditCardHandleService;
use App\Services\RepaymentAccountWithdrawService;
use Illuminate\Http\Request;

class CreditCardHandleController extends BaseController
{
    protected $creditCardHandleService;
    protected $creditCardHandleApplyService;

    public function __construct(CreditCardHandleService $creditCardHandleService,
                                CreditCardHandleApplyService $creditCardHandleApplyService)
    {
        parent::__construct();
        $this->creditCardHandleService = $creditCardHandleService;
        $this->creditCardHandleApplyService = $creditCardHandleApplyService;
    }

    /**
     * 获取办卡列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getHandleCardList(Request $request)
    {
        return $this->creditCardHandleService->getHandleCardList($request->page, $this->user['level'], $this->user['user_id']);
    }

    /**
     * 办卡查询进度
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function selectHandleResult(Request $request)
    {
        return $this->creditCardHandleService->selectHandleResult($request->page);
    }

    /**
     * 办卡规则
     * @return \Illuminate\Http\JsonResponse
     */
    public function handleRules()
    {
        return $this->creditCardHandleService->handleRules();
    }

    /**
     * 申请办卡
     * @param CreditCardHandleApplyRequest $creditCardHandleApplyRequest
     * @return bool|\Illuminate\Http\JsonResponse
     */
    public function apply(CreditCardHandleApplyRequest $creditCardHandleApplyRequest)
    {
        return $this->creditCardHandleApplyService->apply($this->user['user_id'], $creditCardHandleApplyRequest->mobile,
            $creditCardHandleApplyRequest->verification_code, removeSpaceString($creditCardHandleApplyRequest->true_name),
            $creditCardHandleApplyRequest->id_card, $creditCardHandleApplyRequest->credit_card_handle_id);
    }

    /**
     * 分享链接
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function shareUrl(Request $request)
    {
        if (empty($request->credit_card_handle_id)) {
            return $this->responseJson(422);
        }
        return $this->creditCardHandleApplyService->getShareUrl($this->user['user_id'], $request->credit_card_handle_id);
    }


}